Repository navigation
Conversation
…rmance This allows sharing the cache slots on a real (i.e. non-fake) closure's op_array. We can write the scope into the arena region itself so we can easily compare against it.
AWS x86_64 (c6id.metal)
Laravel 12.11.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)
Symfony 2.8.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)
Wordpress 6.9 main page - 50 iterations, 20 warmups, 20 requests (sec)
bench.php - 50 iterations, 20 warmups, 2 requests (sec)
|
|
This is the idea from GH-10782, as in #18556. Output matches master on a differential test across scopes. Zend, opcache and zend_test tests pass under ASan with and without opcache. Change in cycles against master with opcache on, negative = fewer cycles (faster):
The trait and empty closure rows run the same instructions as master, within 0.5%. Pages run 0.1–0.5% fewer. So I think the slower rows are code layout, like on #18556. It also fixes part of GH-25380. A method that creates a closure with a Could you add a test? observer_closure_04.phpt from #18556 fails on master with opcache and passes here. One difference from #18556 is closures with no cache slots. They get a new |
|
I missed something like this was tries before in #18556 |
iliaal
left a comment
There was a problem hiding this comment.
With OPcache on and JIT off, Cachegrind counted 31% fewer instructions per closure creation and call in class scope, but 46% more when one class-scoped call preceded repeated global-scope calls. Both figures are relative to the merge base. Please include observer_closure_04.phpt from GH-18556. It fails on the base and passes here.
| if (!ptr) { | ||
| void **mem = zend_arena_alloc(&CG(arena), sizeof(void *) + func->op_array.cache_size); | ||
| mem[0] = scope; | ||
| ptr = mem + 1; |
There was a problem hiding this comment.
On ARMv7, mem + 1 shifts the cache by four bytes, misaligning the eight-byte zval slots used by ZEND_RECV_INIT. Round the prefix up to ZEND_MM_ALIGNMENT and store the scope immediately before the aligned cache.
| mem[0] = scope; | ||
| ptr = mem + 1; | ||
| memset(ptr, 0, func->op_array.cache_size); | ||
| ZEND_MAP_PTR_SET(func->op_array.run_time_cache, ptr); |
There was a problem hiding this comment.
With OPcache on, two closures from the same factory partially apply a trait method and then its alias. The alias calls Child::main() here but calls the trait method on the merge base. zp_get_op_array() keys both names by their shared opcodes. Please key named methods by function identity, as zend_accel_pfa_key() does, and add a PHPT.
| memset(ptr, 0, func->op_array.cache_size); | ||
| ZEND_MAP_PTR_SET(func->op_array.run_time_cache, ptr); | ||
| } else if ((func->common.fn_flags & ZEND_ACC_HEAP_RT_CACHE) | ||
| || ((zend_class_entry **)ptr)[-1] != scope) { |
There was a problem hiding this comment.
Extensions can initialize this cache through zend_init_func_run_time_cache(), which allocates exactly cache_size bytes. That leaves no scope slot at ptr[-1]. Both allocation paths need the same layout.
This allows sharing the cache slots on a real (i.e. non-fake) closure's op_array. We can write the scope into the arena region itself so we can easily compare against it.